home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Shout3Ddemo / S3D_2E1.exe / Shout3d_runtime / codebase / custom_nodes / DEFNamePickerEffect.java < prev    next >
Text File  |  2000-10-27  |  3KB  |  109 lines

  1. /**
  2.     Company:        Eyematic Interfaces
  3.     Project:        Shout3D Core
  4.     Class:            DEFNamePickerEffect
  5.     Date:            June 7, 2000
  6.     Description:    A simple example of a PostRenderEffect that displays the DEF Name of a picked object
  7.     (C) Copyright Eyematic Interfaces, Inc. - 1997/1998/1999/2000 - All rights reserved
  8.  */
  9.  
  10. package custom_nodes;
  11.  
  12. import shout3d.core.*;
  13. import shout3d.*;
  14. import shout3d.core.awt.*;
  15. import java.awt.*;
  16. import java.awt.image.*;
  17.  
  18. /**
  19.  * DEFNamePickerEffect
  20.  * 
  21.  * @author Jim Stewartson
  22.  * @author Hugues Labbe
  23.  * @author Paul Isaacs
  24.  * 
  25.  */
  26.  
  27. public class DEFNamePickerEffect extends LabelEffect implements DeviceObserver
  28. {
  29.  
  30.     Picker picker;
  31.     int x;
  32.     int y;
  33.     boolean mouseIsInPanel = false;
  34.  
  35.     /**
  36.      * Constructs a default DEFNamePickerEffect node.
  37.      */
  38.     public DEFNamePickerEffect()
  39.     {
  40.         super();
  41.     }
  42.     
  43.     /**
  44.      * When the viewer is set, register with it to receive DeviceInput.
  45.      */
  46.     public void setViewer(Shout3DViewer v){
  47.         // Unregister with old viewer
  48.         if (getViewer() != null)
  49.             getViewer().getDeviceListener().removeDeviceObserver(this, "MouseInput");
  50.         // Change viewers.        
  51.         super.setViewer(v);
  52.         // Register with new viewer
  53.         if (getViewer() != null){
  54.             getViewer().getDeviceListener().addDeviceObserver(this, "MouseInput", null);
  55.             picker = getViewer().getNewPicker();
  56.         }
  57.     }
  58.  
  59.     public boolean onDeviceInput(DeviceInput di, Object userData)
  60.     {
  61.         if ( !(di instanceof MouseInput))
  62.             return false;
  63.  
  64.         MouseInput mi = (MouseInput)di;
  65.         switch (mi.which) {
  66.             case MouseInput.DOWN:
  67.             case MouseInput.DRAG:
  68.             case MouseInput.MOVE:
  69.                 x = mi.x;
  70.                 y = mi.y;
  71.                 mouseIsInPanel = true;
  72.                 break;
  73.             case MouseInput.ENTER:
  74.                 mouseIsInPanel = true;
  75.                 break;
  76.             case MouseInput.EXIT:
  77.                 mouseIsInPanel = false;
  78.                 break;
  79.             default:
  80.                 break;
  81.         }
  82.         return false;
  83.     }
  84.  
  85.     public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight)
  86.     {
  87.         if (mouseIsInPanel) {
  88.             Node[] node = picker.pickClosest(x, y);
  89.             if (node == null)
  90.                 return;
  91.  
  92.             // Get name of bottom-most named node on the path:
  93.             String DEFName = null;
  94.             for (int i = node.length-1; i >= 0; i--) {
  95.                 if (node[i].getDEFName() != null) {
  96.                     DEFName = node[i].getDEFName();
  97.                     break;
  98.                 }
  99.             }
  100.             if (DEFName != null) {
  101.                 label_text.setValue(DEFName);
  102.                 int offsety = 21; 
  103.                 xPosition.setValue(x);
  104.                 yPosition.setValue(y+offsety);
  105.                 super.filter(g, surface_pixel_bits, z_buffer, deviceWidth, deviceHeight);
  106.             }
  107.         }
  108.     }
  109. }